home *** CD-ROM | disk | FTP | other *** search
- Path: tuegate.tue.nl!not-for-mail
- From: pwk@news.eb.ele.tue.nl (Pieter Kuppens)
- Newsgroups: comp.lang.c++,comp.lang.c
- Subject: Q: follow(expect,ifyes,ifno) buggy?
- Date: 27 Feb 1996 15:51:37 GMT
- Organization: Eindhoven University of Technology, Digital Information Systems Group
- Message-ID: <4gv9a9$nfu@tuegate.tue.nl>
- NNTP-Posting-Host: red.eb.ele.tue.nl
- X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
-
- In compiler construction (with C) the following function is often used:
-
- follow(expect,ifyes,ifno)
- {
- int c = getchar();
- if (c==expect) return ifyes;
- ungetc(c,stdin);
- return ifno;
- }
-
- I have my doubts on this function. If calls are nested:
- (abbrev. LA (look ahead) instead of follow)
- LA('/',LA('/',COMMENT_LINE,LA('*',COMMENT,DIV)))
- may very well fail on the following:
- nested call LA is evaluated in the function call, before another
- function LA is completed. Look ahead at 1 position further can disturb
- correct evaluation of this function.
-
- Questions:
- (1) am I right in the expected problem?
- (2) how can this problem be evaded
- (3) is there an C++ equivalent of this function (without the problem)
- (4) if tokens '/' , '//' and '/*' can be recognised, what is the
- best form for the LA( , , ) function?
-
- Regards,
- Pieter Kuppens --- pwk@eb.ele.tue.nl
- Eindhoven University of Technology --- EH 11.24 --- (+31)40-247 3394
- E.S.V.V. Pusphaira on WWW; http://www2.stack.urc.tue.nl/Pusphaira/
-